package com.quanshu.exchange.ui.gui.profile;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.Gravity;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.quanshu.exchange.R;
import com.quanshu.exchange.support.utils.RxViewHelper;

import butterknife.BindView;
import butterknife.ButterKnife;
import io.reactivex.subjects.BehaviorSubject;

public class DialogSaveImg extends Dialog {


    @BindView(R.id.tv_save)
    TextView tvSave;
    @BindView(R.id.tv_cancel)
    TextView tvCancel;

    public BehaviorSubject getSaveSubject() {
        return saveSubject;
    }

    private BehaviorSubject saveSubject = BehaviorSubject.create();


    public DialogSaveImg(@NonNull Context context) {
        super(context, R.style.BaseDialog);
        Window window = getWindow();
        window.setGravity(Gravity.CENTER);
        window.setWindowAnimations(R.style.BottomAnim);
        //默认的Dialog只有5/6左右的宽度，改为全屏宽度
        window.getDecorView().setPadding(0, 0, 0, 0);
        WindowManager.LayoutParams lp = window.getAttributes();
        lp.width = WindowManager.LayoutParams.MATCH_PARENT;
        lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
        window.setAttributes(lp);

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_save_img);
        ButterKnife.bind(this);

        initListener();
    }

    private void initListener() {

        RxViewHelper.getInstance().clicks(tvSave, o -> saveSubject.onNext(o));

        RxViewHelper.getInstance().clicks(tvCancel, aVoid -> cancel());

    }
}
